package com.haotunet.app.goldtreasure.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.DepositOrder;
import com.haotunet.app.goldtreasure.views.TitleView;

public class OrderSuccessActivity extends BaseActivity {
	private TitleView mTitleView;
	private TextView tvReseverAccount, tvReseverTime, tvReseverShop, tvReseverAddress, tvReseverShopCall;
	private TextView btn_return;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_order_success);
		initView();
	}

	private void initView() {

		Intent intent = this.getIntent();
		DepositOrder depositOrder = (DepositOrder) intent.getSerializableExtra("depositorder");
		mTitleView = (TitleView) findViewById(R.id.title_view);
		mTitleView.getTitletextView().setVisibility(View.VISIBLE);
		mTitleView.getTitletextView().setText("预约成功");
		mTitleView.getBackView().setVisibility(View.VISIBLE);
		mTitleView.getBackView().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				skipToMain();
			}
		});
		tvReseverAccount = (TextView) findViewById(R.id.txt_resever_account);
		tvReseverTime = (TextView) findViewById(R.id.txt_resever_time);
		tvReseverShop = (TextView) findViewById(R.id.txt_resever_shop);
		tvReseverAddress = (TextView) findViewById(R.id.txt_resever_address);
		tvReseverShopCall = (TextView) findViewById(R.id.txt_resever_shop_phone);
		tvReseverAccount.setText(depositOrder.getContact());
		tvReseverTime.setText(depositOrder.getReserveTime());
		tvReseverShop.setText(depositOrder.getShopName());
		tvReseverAddress.setText(depositOrder.getShopAddress());
		tvReseverShopCall.setText(depositOrder.getShopPhone());
		btn_return = (TextView) findViewById(R.id.btn_return);
		btn_return.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				skipToRecord();
			}
		});
	}

	private void skipToMain() {
		Intent intent = new Intent();
		intent.setClass(OrderSuccessActivity.this, MainActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtra("type", "");
		startActivity(intent);
	}

	private void skipToRecord() {
		Intent intent = new Intent();
		intent.setClass(OrderSuccessActivity.this, TransRecordActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtra("type", "depositSuccess");
		startActivity(intent);
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			skipToMain();
		}
		return super.onKeyUp(keyCode, event);
	}
}
